<template>
  <div>
    <!-- 选题确认 -->
    <el-form>
      <template>
        <el-table :data="tableData" style="width: 100%">
          <el-table-column label="姓名" width="180">
            <template slot-scope="scope">
              <router-link
                :to="{ path: '/studentinfo', query: { id: scope.row.id } }"
              >
                {{ scope.row.student_name }}
              </router-link>
            </template>
          </el-table-column>
          <el-table-column label="学号" width="180">
            <template slot-scope="scope">
              <p>{{ scope.row.student_num }}</p>
            </template>
          </el-table-column>
          <el-table-column label="专业" width="180">
            <template slot-scope="scope">
              <p>{{ scope.row.student_class }}</p>
            </template>
          </el-table-column>
          <el-table-column label="课题" width="250">
            <template slot-scope="scope">
              <p>{{ scope.row.topic_name }}</p>
            </template>
          </el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button
                size="mini"
                @click="handleEdit(scope.$index, scope.row)"
                >通过
              </el-button>
              <el-button size="mini" @click="unhandle(scope.$index, scope.row)"
                >不通过
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </template>
    </el-form>
  </div>
</template>
<script>
export default {
  created() {
    this.getstudentinfo();
  },
  data() {
    return {
      tableData: [],
    };
  },
  methods: {
    // 获取所带学生信息
    getstudentinfo() {
      this.$http.get("http://127.0.0.1:8080/teacher/gettopic").then((res) => {
        // console.log(res);
        if (res.data.status == 0) {
          res.data.data.result.forEach((value) => {
            res.data.data.results.forEach((val) => {
              if (value.student_num === val.student_num) {
                Object.assign(value, { topic_name: val.topic_name });
              }
            });
          });
          this.tableData = res.data.data.result;
        } else {
          this.tableData = [];
        }
        // console.log(this.tableData);
        // console.log(this.tableData.student_name);
      });
    },

    // 按钮时间----------------------------------------!!!!!!!!!!
    handleEdit(index, row) {
      console.log(row);

      const student_num = row.student_num;
      this.$http
        .post(
          "http://127.0.0.1:8080/teacher/updatebutton",
          this.$qs.stringify(row)
        )
        .then((res) => {
          // console.log(res);
          this.getstudentinfo();
        });
    },
    // 不通过学生的选题
    unhandle(index, row) {
      this.$http
        .post(
          "http://127.0.0.1:8080/teacher/unpass_choose",
          this.$qs.stringify(row)
        )
        .then((res) => {
          // console.log(res);
          if (res.data.status == 0) {
            this.getstudentinfo();
          } else {
            this.$message.error(res.data.message);
          }
        })
        .catch((err) => {
          this.$message.error(err);
        });
    },
  },
};
</script>
<style lang="less" scoped>
</style>
